﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Net.Mime;
using System.IO;


/// <summary>
/// Summary description for Mail
/// </summary>
public class Mail
{
    /*
    private string _fullname;
    private string _phongban;
    private string _nghitungay;
    private string _nghidenngay;
    private string _thoigiannghi;
    */
    NghiPhep n = new NghiPhep();
    public Mail()
    { 
    
    }
	


    public bool ValidMail(string s)
    {
        Regex regEmail = new Regex(@"^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
        if (regEmail.IsMatch(s))
            return true;
        else return false;
    }
    /*
    public void SendMail(string from, string to, string subject, int nCaseForSendMail)
    {

        string strMessageBody;
        string strLogo = string.Empty;
        AlternateView alternateView;
        StreamReader streamReader = null;

        //doc file template html
        if (nCaseForSendMail == 1)//new user
        {
            streamReader = new StreamReader(HttpContext.Current.Server.MapPath("~/mail/mail_new_user.htm"));
            streamReader = File.OpenText(HttpContext.Current.Server.MapPath("~/mail/mail_new_user.htm"));

        }
        else if (nCaseForSendMail == 2)//forgot password
        {
            streamReader = new StreamReader(HttpContext.Current.Server.MapPath("~/mail/mail_forgot_password.htm"));
            streamReader = File.OpenText(HttpContext.Current.Server.MapPath("~/mail/mail_new_user.htm"));

        }

        string strContentHtml = streamReader.ReadToEnd();
        streamReader.Close();

        //thay cac thong tin can thiet
        strMessageBody = strContentHtml.Replace("<Ten_Ung_Vien>", this._fullname);
        strMessageBody = strMessageBody.Replace("<phongban>", this._phongban);
        
        strMessageBody = strMessageBody.Replace("<image logo here>", "<img src=cid:imgLogo />");

        strLogo = HttpContext.Current.Server.MapPath(@"../images/logo.png");
        LinkedResource logo = new LinkedResource(strLogo);
        logo.ContentId = "imgLogo";
        ContentType mimeType = new System.Net.Mime.ContentType("text/html");
        alternateView = AlternateView.CreateAlternateViewFromString(strMessageBody, mimeType);

        alternateView.LinkedResources.Add(logo);

        System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage(from, to);
        mailMessage.AlternateViews.Add(alternateView);
        mailMessage.Body = strMessageBody;

        mailMessage.IsBodyHtml = true;
        mailMessage.Subject = subject;
        SmtpClient s = new SmtpClient("192.168.0.100");
        s.Send(mailMessage);


    }*/
}
